<template>
  <footer class="fixed-bottom footer">
    <cube-tab-bar
      v-model="selectedLabel"
      @click="clickHandler"
      @change="changeHandler"
      :class="'border-top-1px'"
      >
      <cube-tab :class="'border-right-1px'" v-for="(item, index) in tabs" :label="item.label" :icon="item.icon" :key="item.label" :value="index"></cube-tab>
    </cube-tab-bar>
  </footer>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      currentIndex: {
        type: Number,
        default: 0
      }
    },
    created() {
      this.selectedLabel = this.currentIndex
    },
    data () {
      return {
        selectedLabel: 0,
        tabs: [
          {
            label: '首页',
            icon: '',
            link: '/market/debit-credit'
          },
          {
            label: '来领钱',
            icon: '',
            link: '/market/products/9/1'
          },
          {
            label: '一定借到钱',
            icon: '',
            link: '/market/products/10/2'
          },
          {
            label: '我的',
            icon: '',
            link: '/account'
          }
        ]
      }
    },
    methods: {
      clickHandler (index) {
        // this.$emit('onTabClick', this.tabs[index])
      },
      changeHandler (index) {
        this.$router.push(this.tabs[index].link)
        this.$emit('onTabChange', this.tabs[index])
      }
    }
  }
</script>

<style lang="stylus" type="text/stylus">
  @import "../../common/stylus/variable.styl"
  
  .footer
    background: $color-white
    .cube-tab-bar
      .cube-tab
        padding: 15px 0px
        text-align: center
</style>
